package clientserver;

import java.io.Serializable;

import com.mysql.jdbc.ResultSet;

/**
 * This  serializable class  is sent from client to server.
 *  
 * using Packet.type server knows what to do with received packet
 * and client knows what is intended result  which he waiting  r from the server
 * @author Maxim Rahman
 *
 */
public class Packet  implements Serializable{

	private static final long serialVersionUID = -1676257808239763183L;
public enum   PacketType
 {
 SELECT,UPDATE,GETDATE,SAVEFILE,GETFILE,SERVER_QUERY_ANSWER;
 }
    public PacketType  type;
  public Object   data; // could be or SQL query (type==EXECUTESQL) or filename ( in other cases)



 public void setUpdatePacket()   // to set packet for executing mySQL query on server
 {
	 type=PacketType.UPDATE;

 }
 public void setGetFilePacket()   // to set packet for executing mySQL query on server
 {
	 type=PacketType.GETFILE;

 }


 
 public void saveFile( String filename)  // set packet for saving file on server
 {
	 type=PacketType.SAVEFILE;

 }
 
 // constructors ////////////////////////////////////
 public  Packet(String q)  // by default constructor create execute sql query
 {
	 type=PacketType.SELECT;
	 data=q;	 
 }
 public  Packet(AttachedFile file)  // constructor to send files to server side
 {
	 type=PacketType.SAVEFILE;
	 data=file;
	 
 }
 public Packet () 
 {
	 data=null;
	 type=PacketType.GETDATE;
 }
 //////////////////////////////////////////////////

 
}
